package com.ygqh.baby.service;

import com.ygqh.baby.ao.*;
import com.ygqh.baby.model.*;
import com.ygqh.baby.po.YgOrder;
import com.ygqh.baby.po.YgUser;
import com.ygqh.baby.po.YgUserBalance;
import com.ygqh.baby.po.YgUserBalanceDetail;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author admin
 */
public interface YgUserBalanceService {

	List<YgUserBalance> find();

	int findCount();

	YgUserBalance findById(Long id);

	YgUserBalance findByUserId(Long userId);

	YgUserBalance findByUserId(Long userId, String platformNo);

	List<YgUserBalanceDetail> findUserBalanceDetailByUserId(Long userId);

	int save(YgUserBalance ygUserBalance);

	int update(YgUserBalance ygUserBalance);

	int saveOrUpdate(YgUserBalance ygUserBalance);

	/**
	 * 获取联盟用户管理列表
	 * 
	 * @param queryInfo
	 * @param userName
	 * @param sourceCode
	 * @param q
	 * @return
	 */
	ResultSet<YgUser> search(QueryInfo queryInfo, String userName, String sourceCode, String q, Date startTime,
							 Date endTime, String userType, Long userId);

	ResultSet<YgUser> search(QueryInfo queryInfo, String userName, String sourceCode, String q, String userType,
							 Long userId);

	/**
	 * 联盟用户佣金详细列表
	 * 
	 * @param queryInfo
	 * @param balanceType
	 * @param userId
	 * @param platformNo
	 * @return
	 */
	ResultSet<YgUserBalanceDetail> searchBalanceDetail(QueryInfo queryInfo, BalanceType balanceType, Long userId,
													   String platformNo);

	/**
	 * 获取预收入明细列表
	 * 
	 * @param queryInfo
	 * @param userId
	 * @return
	 */
	@Deprecated
	List<YgUserBalanceDetailModel> findBalanceDetailsByType(QueryInfo queryInfo, Long userId, String balance, String preIncome);
	List<YgUserBalanceDetailModel> findBalanceDetailsByType(QueryInfo queryInfo, Long userId, String balance, String preIncome,
															String platformNo);

	/**
	 * 获取订单返利信息
	 * 
	 * @param id
	 * @return
	 */
	YgUserBalanceOrderDetailModel findOrderBalanceDetail(Long balanceDetailId, Long id);

	YgUserBalanceOrderInfo findOrderBalanceDetailV2(String ubdOrderId, BalanceType balanceType, OperationType operationType, Long userId);

	/**
	 * 获取订单列表
	 * 
	 * @param queryInfo
	 * @param sourceCode
	 * @return
	 */
	List<YgUserBalanceOrderModel> findOrderList(QueryInfo queryInfo, String sourceCode);

	/**
	 * 批量插入收入详细
	 * 
	 * @param detailList
	 * @return
	 */
	int addBalacneDetailByBatch(List<YgUserBalanceDetail> detailList);

	/**
	 * 批量更新用户余额表
	 * 
	 * @param balanceList
	 * @return
	 */
	int updateUserBalanceByTask(List<YgUserBalance> balanceList);

	/**
	 * 批量更新可提现金额
	 * 
	 * @param balanceList
	 * @return
	 */
	int updateUserBalancePrice(List<YgUserBalance> balanceList);

	/**
	 * 30天后预收入金额转换成可提现金额
	 * 
	 * @return
	 */
	int addPriceTypeToBalance();

	/**
	 * 查询列表通过balanceType和orderIds
	 * 
	 * @param balanceType
	 * @param orderIds
	 * @return
	 */
	List<YgUserBalanceDetail> findListByPriceTypeAndOrderIds(BalanceType balanceType, Long[] orderIds);

	List<YgUserBalance> findListByUserIds(List<Long> userIds);

	/**
	 * 查找企业用户预收入明细
	 * 
	 * @param queryInfo
	 * @param userId
	 */
	ResultSet<YgCompanyBalanceDetailModel> findCompanyPreIncomeList(QueryInfo queryInfo, Long userId);

	ResultSet<YgCompanyBalanceDetailModel> findCompanyPreIncomeListByUserId(QueryInfo queryInfo, Long userId, BalanceType type);

	/**
	 * 查找企业用户累计返利明细
	 * 
	 * @param queryInfo
	 * @param userId
	 */
	ResultSet<YgCompanyBalanceDetailModel> findCompanyBalanceList(QueryInfo queryInfo, Long userId);

	/**
	 * 企业预收入返利，按员工聚合查询
	 * 
	 * @param id
	 * @return
	 */
	List<YgCompanyBalanceCollectModel> findPreIncomeCompanyMoneyCollectByUser(Long id);

	/**
	 * 企业累计收入返利，按员工聚合查询
	 * 
	 * @param id
	 * @return
	 */
	List<YgCompanyBalanceCollectModel> findBalanceCompanyMoneyCollectByUser(Long id);

	/**
	 * 预收入总和AND累计收入总和
	 * 
	 * @return
	 */
	Map<String, Object> findCompaneyPreIncomeAndBalanceSum(Long userId);

	/**
	 * 根据渠道获取该渠道的推广订单数量及订单金额（）
	 * 
	 * @param sourceCode
	 * @return
	 */
	BiChannelModel findChannelBi(String sourceCode);

	/**
	 * 扣减账户余额
	 * 
	 * @param userId
	 * @param accountPrice
	 * @return
	 */
	int reduceAcountPrice(Long userId, BigDecimal accountPrice);

	int reduceAcountPrice(Long userId, BigDecimal accountPrice, String platformNo);

	/**
	 * 还账户余额
	 * 
	 * @param userId
	 * @param accountPrice
	 * @return
	 */
	int backAcountPrice(Long userId, BigDecimal accountPrice);

	int backAcountPrice(Long userId, BigDecimal accountPrice, String platformNo);

	/**
	 * 后台充值虚拟账户
	 * 
	 * @param price
	 * @param id
	 * @return
	 */
	Message recharge(String phone, BigDecimal price, String remark, String createBy);

	/**
	 * 红包充值
	 * 
	 * @param phone
	 * @param price
	 * @param remark
	 * @param createBy
	 * @return
	 */
	Message redPacketRecharge(String phone, BigDecimal price, String remark, String createBy);

	/**
	 * 充值成长基金
	 * 
	 * @param userId
	 * @param price
	 * @param operationType
	 * @param remark
	 * @param createBy
	 * @return
	 */
	Message incomeRecharge(Long userId, BigDecimal price, OperationType operationType, String relationId,
						   String remark, String createBy);

	Message updateRate(Long userId, BigDecimal shareRate, BigDecimal foreverRate);

	/**
	 * 批量还红包余额
	 * 
	 * @param orderList
	 *            （userId,accountPrice 必须项）
	 * @return
	 */
	int backAcountPriceBatch(List<YgOrder> orderList);

	List<YgUserBalanceDetail> findBalanceForCommissionDetail(Long userId);

	/**
	 * 返利明细中可用于提现的金额
	 * 
	 * @param userId
	 * @return
	 */
	Map<String, Object> findTotalBalancePriceForCommission(Long userId);
	Map<String,Object> findTotalBalancePriceForCommission(Long userId, String platformNo);

	/**
	 * 更新可提现明细中申请单状态
	 * 
	 * @param userId
	 * @param commissionId
	 * @param commissionStatus
	 * @param isApply
	 * @param maxId
	 * @return
	 */
	int updateBalanceDetailByCommission(Long userId, Long commissionId, CommissionStatus commissionStatus,
										Boolean isApply, Long maxId, String platformNo);

	YgUserBalanceDetail findBalanceDetail(Long userId, Long orderId, RebateType rebateType, BalanceType priceType);

	@Deprecated
	int addBalanceDetail(Long userId, String orderId, BigDecimal accountPrice, BalanceType balance,
						 OperationType operationType, String remark);
	int addBalanceDetail(Long userId, String orderId, BigDecimal accountPrice, BalanceType balance,
						 OperationType operationType, String remark, String platformNo);

	/**
	 * 获取该申请单中返利明细
	 * 
	 * @param commissionId
	 * @param userId
	 * @return
	 */
	@Deprecated
	List<YgUserBalanceDetail> findBalanceDetailByCommissionId(Long commissionId, Long userId);
	List<YgUserBalanceDetail> findBalanceDetailByCommissionId(Long commissionId, Long userId, String platformNo);

	List<BalanceDiff> findDifference(BalanceType bType);
	List<BalanceDiff> findDifference(BalanceType bType, boolean splitPlatform);

	/**
	 * 校验成长基金是否充足 </br>
	 * checkPrice <= balancePrice
	 * 
	 * @Title: checkBalance
	 * @param accountPrice
	 * @param userId
	 *            入参
	 * @return Message 返回类型
	 * @author （guohao）
	 * @throws @date
	 *             2017年8月22日 下午1:54:11
	 * @version V1.0
	 */
	Message checkBalance(BigDecimal checkPrice, Long userId);

	/**
	 * 重置用户账户信息(只适用于不拆分平台)
	 *
	 * @param balanceType 账户类型
	 * @param userId 用户id集
	 * @return
	 */
	int resetUserBalance(BalanceType balanceType, List<Long> userId);

	/**
	 * 重置用户账户信息
	 *
	 * @param balanceType 账户类型
	 * @param userIds 用户id集
	 * @param splitPlatform 是否拆分平台
	 * @return
	 */
	int resetUserBalance(BalanceType balanceType, List<Long> userIds, boolean splitPlatform);

	Map<String, Object> getUserShareOrderPrice(Long userId);

	List<YgUserShareOrderModel> getUserShareOrder(QueryInfo queryInfo, YgUser user);

	YgUserShareOrderModel findShareOrderInfo(Long orderId);

	/**
	 * 将原用户的成长基金转移到目标用户下
	* @Title: transferBalance 
	*  @param sourceUserId
	*  @param targetUserId
	*  @return    入参
	* @return int    返回类型
	* @author （guohao） 
	* @throws
	* @date 2018年5月10日 下午6:48:43 
	* @version V1.0
	 */
	int transferBalance(Long sourceUserId, Long targetUserId);

	/**
	 * 重新计算该用户的 预收入，可提现，已提现金额（不拆分平台）
	* @Title: resetUserBalance 
	*  @param userIds
	*  @return    入参
	* @return int    返回类型
	* @author （guohao） 
	* @throws
	* @date 2018年5月11日 上午10:12:15 
	* @version V1.0
	 */
	int resetUserBalance(Long... userIds);

	void processUserBalance(Long userId);

	void processUserBalance(Long userId, String platformNo);
}
